package com.example.brazil_project;

import java.util.ArrayList;
import java.util.List;

import com.example.brazil_project.function.Public_method;
import com.example.brazil_project.util.WebviewSetting;








import android.app.Activity;
import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;

public class CopyOfMainActivity extends Activity {
	 private ViewPager viewPager;  //对应的viewPager 
	  private List<View> viewList;//view数组 
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		WebView webview = WebviewSetting.getWebview(this,"file:///android_asset/userinfo.html");
		
				
		WebView webview1 = WebviewSetting.getWebview(this,"file:///android_asset/login.html");
		WebView webview2 = WebviewSetting.getWebview(this,"file:///android_asset/document.html");
		WebView webview3 = WebviewSetting.getWebview(this,"file:///android_asset/document_detail.html");
		
		
		viewPager = (ViewPager) findViewById(R.id.viewpager);  
		viewList = new ArrayList<View>();// 将要分页显示的View装入数组中  
		viewList.add(webview);  
		viewList.add(webview2);  
		viewList.add(webview1);  
		viewList.add(webview3);  
		
		
	
		 PagerAdapter pagerAdapter = new PagerAdapter() {  
             
	            @Override  
	            public boolean isViewFromObject(View arg0, Object arg1) {  
	                // TODO Auto-generated method stub  
	                return arg0 == arg1;  
	            }  
	              
	            //getCount():返回要滑动的VIew的个数
	            @Override  
	            public int getCount() {  
	                // TODO Auto-generated method stub  
	                return viewList.size();  
	            }  
	              
	            //destroyItem（）：从当前container中删除指定位置（position）的View;
	            @Override  
	            public void destroyItem(ViewGroup container, int position,  
	                    Object object) {  
	                // TODO Auto-generated method stub  
	                container.removeView(viewList.get(position));  
	            }  
	              
	            //instantiateItem()：做了两件事，第一：将当前视图添加到container中，第二：返回当前View
	            @Override  
	            public Object instantiateItem(ViewGroup container, int position) {  
	                // TODO Auto-generated method stub  
	                container.addView(viewList.get(position));  
	                  
	                  
	                return viewList.get(position);  
	            }  
	        };  
	          
	          
	        viewPager.setAdapter(pagerAdapter);  

		
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}
}
